﻿namespace SvGame.Logic;

public static partial class GameLogic
{
    /// <summary>
    /// 尝试把断线超过 15 分钟未登出的玩家登出
    /// </summary>
    public static void TryPlayersLogoutDisconnect()
    {
        long ticksCompare = DateTime.Now.AddMinutes(-5).Ticks;
        var players = (from it in DictPlayer.Values
                       where (!it.Online && it.TicksDisconnect <= ticksCompare)
                       select it).ToList();
        foreach (var player in players)
        {
            player.PlayerLogout();
            DbRedis.ZSave(player);
        }
    }
    /// <summary>
    /// 尝试自动存盘 每 15 分钟
    /// </summary>
    public static void TryPlayersAutoSave()
    {
        long ticksCompare = DateTime.Now.Ticks;
        var players = (from it in DictPlayer.Values
                       where (it.Online && ticksCompare >= it.TicksAutoSave)
                       select it).ToList();
        foreach (var player in players)
        {
            DbRedis.ZSave(player);
            player.TicksAutoSaveSet();
        }
    }
}
